<?
ob_start();

session_start();
include('../src/inst.conf.php');


if(isset($_GET['logoff'])){session_destroy();header("location: ".$_SERVER['PHP_SELF']."");}
if (!isset($_SESSION['LOGIN_USERNAME'] ) || !isset( $_SESSION['LOGIN_PASSWORD'] )){ 
		header("location: ./index.php");
		exit; 
		
}

ob_end_flush();
$result = mysql_query("SELECT * FROM `DOCENT` WHERE `DOCENT_ID` = '".$_SESSION['LOGIN_ID']."'"); 
$row = mysql_fetch_array($result);
?>
<script src="./src/jquery-1.7.1.min.js"  type="text/javascript"></script>
<script src="./src/jquery.notify.js"     type="text/javascript"></script>
<script src="./src/LAL.plugin.js.php"    type="text/javascript"></script>
<script src="./src/jquery.idle-timer.js" type="text/javascript"></script>
<script src="./src/vibarate.js"          type="text/javascript"></script>
<script>
function VerzendGegevens(welk){
	$("#TableForm").find('tr').css("color", "");
	showLoader('Opslaan..', 'Gegevens worden opgeslagen in de database');
    var send_data = $("#"+welk).serializeArray();
    var url = "./src/update.user.php?"+welk;
    
    if(welk == 'Algemeen'){
    	$.post(url, { v: $('#v').val(), t: $('#t').val(), a: $('#a').val(), e: $('#e').val(), s: $('#s').val() },function(j){
    		if(j[0].status == "succes"){
    			
    		}else{
    			$.notify({text: j[0].errorText, title: j[0].errorTitle, icon:'images/dialog-error.png'});
    			$.each(j.errorField, function(key, value) { 
    			  $("#"+value).parent().parent().css('color', 'red'); 
    			});	
    		}
    	 }, 'json');
   	}else if(welk == 'Wachtwoord'){
   		$.post(url, { u: $('#u').val(), p_o: $('#p_o').val(), p_n: $('#p_n').val(), p_n2: $('#p_n2').val() },function(j){
   			if(j.status == "succes"){
   				$.notify({text: j.Text, title: j.Title, icon:'images/dialog-done.png'});
   				$('#p_o').val('');
   				$('#p_n').val('');
   				$('#p_n2').val('');
   				$('#p_n').parent().parent().fadeIn('fast');
   				$('#p_n2').parent().parent().fadeIn('fast');
   				$("#TableForm").find('tr').css("color", "");
   				$('#usercheck').html('Huidige gebruikersnaam');
   				$('#usercheck').css('color','#ccc');
   			}else{
   				$.notify({text: j.errorText, title: j.errorTitle, icon:'images/dialog-error.png'});
   				$.each(j.errorField, function(key, value) { 
   				  $("#"+value).parent().parent().css('color', 'red'); 
   				});		
   			}
   		 }, 'json');
   	}
   	hideLoader();    
}

function CheckUserName(){
	$('#usercheck').html("<img src='./images/checking.gif'> controleren...");
	$('#usercheck').css('color','#000');
	var url = "./src/update.user.php";
	$.getJSON(url,
	  {
	    CheckUserName: true,
	    u: $('#u').val()
	  },
	  function(data) {
	   $('#usercheck').html(data.text);
	   $('#usercheck').css('color',data.color);
	   if(data.status == "change"){
	   		$('#p_n').parent().parent().fadeOut();
	   		$('#p_n2').parent().parent().fadeOut();
	   		$('#p_o').parent().parent().find('td:first-child').html('Wachtwoord');
	   }else{
	   		$('#p_n').parent().parent().fadeIn('fast');
	   		$('#p_n2').parent().parent().fadeIn('fast');
	   		$("#TableForm").find('tr').css("color", "");
	   		$('#p_o').parent().parent().find('td:first-child').html('Oud wachtwoord');

	   }
	  });
}
</script>
<div id="left-div">
	<div id="left-inside">
		<div style="clear: both;"></div>
		<div style="clear: both;"></div>								
			<div class="home-post-wrap_full"> 
					<h2 class="titles">Account gegevens</h2>
					<div style="clear: both;"></div>
					<br>
					<table border="0" id="TableForm">
					<!--<form name="Algemeen" id="Algemeen" method="POST">
					<tr><td colspan=2><h3>Algemeen</h3></td></tr>
					<tr><td>Voornaam</td><td><input type="text" name="v" id="v" value="<?=$row['VOORNAAM'];?>" /></td></tr>
					<tr><td>Tussenvoegsel</td><td><input type="text" name="t" id="t" value="<?=$row['TUSSENVOEGSEL'];?>" /></td></tr>
					<tr><td>Achternaam</td><td><input type="text" name="a" id="a" value="<?=$row['ACHTERNAAM'];?>" /></td></tr>
					<tr><td>Email</td><td><input type="text" name="e" id="e" value="<?=$row['E_MAIL_ADRES'];?>" /></td></tr>
					<tr><td>Geslacht</td><td><select name="s" id="s">
													<?if($row['GESLACHT'] == null){echo "<option disabled selected>-Kies-</option>";}?>
													<option value="M" <?if($row['GESLACHT'] == "M"){echo "selected";}?>>Man</option>
													<option value="V" <?if($row['GESLACHT'] == "V"){echo "selected";}?>>Vrouw</option>
											 </select></td></tr>
					<tr><td colspan=2><div class="but"><a href="javascript:void('0');" class="regular" name="save" id="save_butt" onclick="VerzendGegevens('Algemeen');"><img src="images/icon-save.png" alt=""/>Opslaan</a></div></td></tr>
					</form>-->
					<tr><td colspan=2></td></tr>
					<form name="Wachtwoord" id="Wachtwoord">
					<tr><td colspan=2><h3>Inloggegevens</h3></td></tr>
					<tr><td>Gebruikersnaam</td><td><input type="text" name="u" id="u" value="<?=$row['GEBRUIKERSNAAM'];?>" onkeyup="CheckUserName();"/></td><td id="usercheck" rowspan="4" style="vertical-align:top;color: #ccc;">Huidige gebruikersnaam</td></tr>
					<tr><td>Oud Wachtwoord</td><td><input type="password" name="p_o" id="p_o" value="" /></td></tr>
					<tr><td>Nieuw wachtwoord</td><td><input type="password" name="p_n" id="p_n" value="" /></td></tr>
					<tr><td>Nieuw wachtwoord</td><td><input type="password" name="p_n2" id="p_n2" value="" /></td></tr>
					<tr><td colspan=2><div class="but"><a href="javascript:void('0');" class="regular" name="save" id="save_butt" onclick="VerzendGegevens('Wachtwoord');"><img src="images/icon-save.png" alt=""/>Opslaan</a></div></td></tr>
					</form>
					
			</div> <!-- end .home-post-wrap2 -->
	</div> <!-- end #left-inside -->
</div> <!-- end #left-div -->